<?php

	class Devmod_method_castField_image extends Devmod_castField_abstraction {
		
		public function type_add()
		{
			// image id: $value
			
			$img = null;
			
			$this->view->assign(array(
				'field_name' => $this->cfg['field_name'],
				'value' => '',
				'img' => $img,
				'theme' => $this->view->theme,
				'type' => 'add'
			));
			
			$this->view->append('tpl_addons', $this->view->fetch('common/cast_image.tpl'));
			
			return $this->view->fetch('common/cast_image_show.tpl');
		}
		
		public function type_edit()
		{
			// image id: $value
			
			$img = null;
			
			if($this->value !== "0" && isset($this->value) && !empty($this->value))
			{
				$img = Image::Show($this->value);
			}
			
			$this->view->assign(array(
				'field_name' => $this->cfg['field_name'],
				'value' => $this->value,
				'img' => $img,
				'theme' => $this->view->theme,
				'type' => 'edit'
			));
			
			$this->view->append('tpl_addons', $this->view->fetch('common/cast_image.tpl'));
			
			return $this->view->fetch('common/cast_image_show.tpl');
		}
		
		public function type_frontend_list()
		{
			if(!isset($this->args['output']) || empty($this->args['output'])) $this->args['output'] = 'portrait';
			
			switch($this->args['output'])
			{
				case "array" :
					return array(
						'small' => Image::Show($this->value, 'small'),
						'portrait' => Image::Show($this->value, 'portrait'),
						'full' => Image::Show($this->value, 'full')
					);
				break;
				
				default :
					return Image::Show($this->value, $this->args['output']);
				break;
			}
		}
		
		public function type_list()
		{
			if(!isset($this->value)) return "no_image";
			
			if(!isset($this->args['output']) || empty($this->args['output'])) $this->args['output'] = 'portrait';
			
			switch($this->args['output'])
			{
				case "array" :
					return array(
						'small' => Image::Show($this->value, 'small'),
						'portrait' => Image::Show($this->value, 'portrait'),
						'full' => Image::Show($this->value, 'full')
					);
				break;
				
				default :
					
					if(Image::Show($this->value, $this->args['output']) == "no_image") return null;
					
					return $this->helper->element('img', array('src' => Image::Show($this->value, $this->args['output']), 'border' => 0));
				break;
			}
		}
		
	}